import { observer } from "mobx-react";
import { Row, Col, Radio } from 'antd';
import { WeaFormItem, WeaInput, WeaSelect, WeaCheckbox, WeaBrowser, WeaTab, WeaLocaleProvider, WeaInputNumber, WeaError, WeaHelpfulTip } from 'ecCom';
import OperatorSet from "./OpreatorSet";
const getLabel = WeaLocaleProvider.getLabel;

@observer
export default class DynamicNodeInfo extends React.Component {
    render() {
        const { store } = this.props;
        const { dynamicNodeForm:form } = store;
        const uuid = form.$('uuid').values();
        const nodetype = form.$("nodeType");
        const operatortype = form.$('operatorType');
        const tablename = form.$('tablename');
        const tablekey = form.$('tablekey');
        const showfield = form.$('showfield');
        const hrmField = form.$('hrmField');
        const sqlWhere = form.$('sqlWhere');
        const isrecursion = form.$('isrecursion');
        const tablesup = form.$('tablesup');
        const relationtype = form.$('relationtype');
        const hrmresource = form.$('hrmresource');
        const hrmdepartment = form.$('hrmdepartment');
        const hrmsubcompany = form.$('hrmsubcompany');
        const rootids = form.$('rootids');
        const supnodefield = form.$('supnodefield');
        const nodefield = form.$('nodefield');
        const nodetypeOptions = [];
        if (uuid === "root") {
            nodetypeOptions.push({
                key: '0',
                showname: getLabel('502714', '静态节点'),
            });
        } else if (store.parentNodeType && store.parentNodeType === '1') {
            nodetypeOptions.push({
                key: '1',
                showname: getLabel('502715', '动态节点'),
            });
        } else {
            nodetypeOptions.push({
                key: '0',
                showname: getLabel('502714', '静态节点'),
            });
            nodetypeOptions.push({
                key: '1',
                showname: getLabel('502715', '动态节点'),
            });
        }
        const nodeTypeValue = nodetype.values();
        const operatorTypeValue = operatortype.values();
        const isDynamic = nodeTypeValue === "1";
        const isStatic = nodeTypeValue === "0";
        const isRecursion = isrecursion.values() == '1';
        const isDynamicCustom = isDynamic && operatorTypeValue === '3';
        const isResource = operatorTypeValue === '0';
        const isDept = operatorTypeValue === '1';
        const isSubCom = operatorTypeValue === '2';
        const isDynamicCustomRecursion = isDynamicCustom && isRecursion;
        const relationtypeValue = relationtype.values();
        const isPointNode = relationtypeValue === '0';
        const isRelateNode = relationtypeValue === '1';
        const isRoot = uuid === "root" ? true : false;
        const relationtypeOptions = [];
        if (store.parentNodeType && store.parentNodeType === '0') {
            relationtypeOptions.push({
                key: '0',
                showname: getLabel('502725', '指定节点'),
            });
        } else {
            relationtypeOptions.push({
                key: '1',
                showname: getLabel('502726', '关联上级节点'),
            });
        }
        const operateTypeOptions = [];
        if (store.parentOperateType) {
            if (store.parentOperateType === '0') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '1') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '1',
                        showname: getLabel(502298, '部门'),
                    }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '2') {
                operateTypeOptions.push({
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                        key: '1',
                        showname: getLabel(502298, '部门'),
                    }, {
                        key: '2',
                        showname: getLabel(502299, '分部'),
                    }, {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            } else if (store.parentOperateType === '3') {
                operateTypeOptions.push(
                    {
                        key: '3',
                        showname: getLabel(502465, '自定义'),
                    });
            }
        } else {
            operateTypeOptions.push(
                {
                    key: '0',
                    showname: getLabel(502300, '人力资源'),
                }, {
                    key: '1',
                    showname: getLabel(502298, '部门'),
                }, {
                    key: '2',
                    showname: getLabel(502299, '分部'),
                }, {
                    key: '3',
                    showname: getLabel(502465, '自定义'),
                });
        }
        const parentTableName = store.parentTableName;
        return (
            <div>
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@3tb66a`}
                    label={getLabel('528258','节点类型') }
                    labelCol={{ span: 6 }}
                    wrapperCol={{ span: 18 }}>
                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@oqjd0p`}
                        {...nodetype.bind()}
                        options={nodetypeOptions}
                        detailtype={3}
                        onChange={store.changeNodeType}
                        value={nodeTypeValue}
                         />
                </WeaFormItem>
                {isDynamic && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@iezhw5`} className="edc-addNode-item-row">
                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@3yso2x`} span={24}>
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ws8hrr`}
                            label={getLabel('502718', '解析类型')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 18 }}

                        >
                            <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@m05wio`}
                                className="edc-addNode-set-select"
                                style={{ width: '280px' }}
                                viewAttr={3}
                                detailtype={3}
                                options={operateTypeOptions}
                                {...operatortype.bind()}
                                onChange={store.changeOperatorType}
                            />
                        </WeaFormItem>
                    </Col>
                </Row>}
                {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@0lwj6f`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@0o8mpo`}
                        label={getLabel('519342', '自定义表名')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}
                        error={form.getError({ domkey: ['tablename'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@q0iozv`}
                            tipPosition='bottom'
                            ref={ref => store.tableNameErr = ref}
                            error={'自定义表名为空'}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@z88o2n`}
                                inputStyle={{ width: 256 }}
                                viewAttr={3}
                                {...tablename.bind()}
                                type={'EdcLocalTables'}
                                title={getLabel('512077', '选择表或视图')}
                                hasAdvanceSerach={true}
                            />
                        </WeaError>
                    </WeaFormItem>
                </Row>}
                {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@dr4qx9`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@pmn4cb`}
                        label={getLabel('519343', '自定义主键')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}
                        error={form.getError({ domkey: ['tablekey'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@yie4be`}
                            tipPosition='bottom'
                            ref={ref => store.tableKeyErr = ref}
                            error={'自定义主键为空'}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@uyozge`}
                                inputStyle={{ width: 256 }}
                                viewAttr={3}
                                {...tablekey.bind()}
                                type={'EdcTableFields'}
                                title={getLabel('512079', '选择字段')}
                                hasAdvanceSerach={true}
                                completeParams={{ tableName: tablename.values() }}
                                dataParams={{ tableName: tablename.values() }}
                            />
                        </WeaError>
                    </WeaFormItem>
                </Row>}
                {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@ieivk0`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@xvxac1`}
                        label={getLabel('30828', '显示名称')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}
                        error={form.getError({ domkey: ['showfield'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@eura2i`}
                            tipPosition='bottom'
                            ref={ref => store.showFieldErr = ref}
                            error={'显示名称为空'}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@p1f9l5`}
                                inputStyle={{ width: 256 }}
                                viewAttr={3}
                                {...showfield.bind()}
                                type={'EdcTableFields'}
                                title={getLabel('512079', '选择字段')}
                                hasAdvanceSerach={true}
                                completeParams={{ tableName: tablename.values() }}
                                dataParams={{ tableName: tablename.values() }}
                            />
                        </WeaError>
                    </WeaFormItem>
                </Row>}
                {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@80iijr`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@zc83yb`}
                        label={getLabel('15549', '人力资源字段')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}
                        error={form.getError({ domkey: ['hrmField'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@z549m2`}
                            tipPosition='bottom'
                            ref={ref => store.hrmFieldErr = ref}
                            error={'人力资源字段为空'}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@y42oxl`}
                                inputStyle={{ width: 256 }}
                                viewAttr={3}
                                {...hrmField.bind()}
                                type={'EdcTableFields'}
                                title={getLabel('512079', '选择字段')}
                                hasAdvanceSerach={true}
                                completeParams={{ tableName: tablename.values() }}
                                dataParams={{ tableName: tablename.values() }}
                            />
                        </WeaError>
                    </WeaFormItem>
                </Row>}
                {isDynamicCustom && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@7uwup3`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@cyuhf1`}
                        label={getLabel('502722', '是否递归解析')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 8 }}
                        error={form.getError({ domkey: ['isrecursion'] })}
                    >
                        <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@270hq3`}
                            helpfulTip={getLabel('502722', '是否递归解析')}
                            display="switch"
                            style={{ display: 'inline' }}
                            {...isrecursion.bind()}
                        />
                    </WeaFormItem>
                </Row>}
                {/*  && */}
                {isDynamicCustomRecursion && <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@du6gnx`} className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@7z73ok`}
                        label={getLabel('502723', '上级字段')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 10 }}
                        error={form.getError({ domkey: ['tablesup'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@2t3w2e`}
                            tipPosition='bottom'
                            ref={ref => store.tableSupErr = ref}
                            error={getLabel('512093', '上级字段为空')}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@a62ckw`}
                                inputStyle={{ width: 256 }}
                                viewAttr={3}
                                {...tablesup.bind()}
                                type={'EdcTableFields'}
                                title={getLabel('512079', '选择字段')}
                                hasAdvanceSerach={true}
                                completeParams={{ tableName: tablename.values() }}
                                dataParams={{ tableName: tablename.values() }}
                            />
                        </WeaError>
                    </WeaFormItem>
                </Row>}
                {isDynamic && isPointNode && isResource &&
                    // <Row className="edc-addNode-item-row">
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2oa1v2`}
                        label={getLabel('502727', '指定对象')}
                        labelCol={{ span: 6 }}
                        wrapperCol={{ span: 18 }}
                        error={form.getError({ domkey: ['hrmresource'] })}
                    >
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@dhozf3`} tipPosition='bottom'
                            ref={ref => store.objBrowserErr = ref}
                            error={getLabel('512094', '指定对象为空')}>
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@0geoou`} inputStyle={{ width: 256 }} viewAttr={3} {...hrmresource.bind()} isSingle={false} type={17} title={getLabel('505966', '选择人员')} />
                        </WeaError>
                    </WeaFormItem>
                    // </Row>
                }
                {isDynamic && isPointNode && isDept &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@80pi4g`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5lj1g0`}
                            label={getLabel('502727', '指定对象')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 18 }}
                            error={form.getError({ domkey: ['hrmdepartment'] })}
                        >
                            <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@ujpfxj`} tipPosition='bottom'
                                ref={ref => store.objBrowserErr = ref}
                                error={getLabel('512094', '指定对象为空')}>
                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@9msl7g`} inputStyle={{ width: 256 }} viewAttr={3} {...hrmdepartment.bind()} isSingle={false} type={57} title={getLabel('505972', '选择部门')} />
                            </WeaError>
                        </WeaFormItem>
                    </Row>
                }
                {isDynamic && isPointNode && isSubCom &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@rcviu7`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@catsew`}
                            label={getLabel('502727', '指定对象')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 18 }}
                            error={form.getError({ domkey: ['hrmsubcompany'] })}
                        >
                            <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@6s8giq`} tipPosition='bottom'
                                ref={ref => store.objBrowserErr = ref}
                                error={getLabel('512094', '指定对象为空')}>
                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@bppr45`} inputStyle={{ width: 256 }} viewAttr={3} {...hrmsubcompany.bind()} isSingle={false} type={194} title={getLabel('505970', '选择分部')} />
                            </WeaError>
                        </WeaFormItem>
                    </Row>
                }
                {isPointNode && isDynamicCustom &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2r70l2`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@v9v7qm`}
                            //label={getLabel('502728', '指定id')}
                            label={getLabel('512095', '指定主键')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 10 }}
                            error={form.getError({ domkey: ['rootids'] })}
                        >
                            <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@xgmjye`}
                                tipPosition='bottom'
                                ref={ref => store.rootIdErr = ref}
                            //error='指定id为空'
                            >
                                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@qlywbe`} style={{ width: 256 }} viewAttr={2} {...rootids.bind()} />
                            </WeaError>

                        </WeaFormItem>
                    </Row>
                }
                {isPointNode && isDynamicCustom &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@8re2iu`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@pp2uo7`}
                            label={getLabel('81445', '数据显示条件')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 10 }}
                        >
                            <div style={{ display: 'flex' }}>
                                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@oj81vi`}
                                    style={{ width: 256 }} viewAttr={2} {...sqlWhere.bind()}
                                />
                                <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@b9acao`} style={{ padding: '5px 0px 0px 5px' }}
                                    title={
                                        <div>
                                            <p>{getLabel('527152','格式')+"：a='1' and b='2' and c='{userid}'"}</p>
                                            <p>{getLabel('527153','动态参数说明：') }</p>
                                            <p>{getLabel('527158','1.输入{userid}表示当前用户id') }</p>
                                            <p>{getLabel('527159','2.输入{subcompanyid}表示用户的分部id') }</p>
                                            <p>{getLabel('527155','3.输入{departmentid}表示用户的部门id') }</p>
                                            <p>{getLabel('527156','4.输入{workcode}表示用户的工作编号') }</p>
                                            <p>{getLabel('527157','5.输入{date}表示当前日期') }</p>
                                        </div>
                                    }
                                    placement="left" />
                            </div>
                        </WeaFormItem>
                    </Row>}
                {isDynamicCustom && isRelateNode &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@72ffzr`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@sz6pgu`}
                            label={getLabel('502729', '上级节点字段')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 8 }}
                            error={form.getError({ domkey: ['supnodefield'] })}
                        >
                            <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@lcff8g`}
                                tipPosition='bottom'
                                ref={ref => store.supnodefieldErr = ref}
                                error={getLabel('512096', '上级节点字段为空')}>
                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@08iq01`}
                                    inputStyle={{ width: 256 }}
                                    viewAttr={parentTableName ? 3 : 1}
                                    {...supnodefield.bind()}
                                    type={'EdcTableFields'}
                                    title={getLabel('512079', '选择字段')}
                                    hasAdvanceSerach={true}
                                    completeParams={{ tableName: parentTableName }}
                                    dataParams={{ tableName: parentTableName }}
                                />
                            </WeaError>
                        </WeaFormItem>
                    </Row>
                }
                {isDynamicCustom && isRelateNode &&
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@2z2msa`} className="edc-addNode-item-row">
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@3a4k2l`}
                            label={getLabel('502730', '本级节点字段')}
                            labelCol={{ span: 6 }}
                            wrapperCol={{ span: 8 }}
                            error={form.getError({ domkey: ['nodefield'] })}
                        >
                            <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@ksvmki`}
                                tipPosition='bottom'
                                ref={ref => store.nodefieldErr = ref}
                                error={getLabel('512098', '本级节点字段为空')}>
                                <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@otz4dv`}
                                    inputStyle={{ width: 256 }}
                                    viewAttr={3}
                                    {...nodefield.bind()}
                                    type={'EdcTableFields'}
                                    title={getLabel('512079', '选择字段')}
                                    hasAdvanceSerach={true}
                                    completeParams={{ tableName: tablename.values() }}
                                    dataParams={{ tableName: tablename.values() }}
                                />
                            </WeaError>
                        </WeaFormItem>
                    </Row>
                }
                {(isDynamic || isStatic) && <OperatorSet ecId={`${this && this.props && this.props.ecId || ''}_OperatorSet@4gkk40`} store={store} />}
            </div>
        )
    }
}